import { setFullscreen, exitFullscreen } from '../utils/utils';
/**
 *  全局model，全局化操作可以在此处实现
 *
 */
const GlobalModel = {
  namespace: 'global',

  state: {
    fullScreen: false,
    collapsed: false,
    breads: [],
  },
  effects: {
    *changeBreads({payload}, {put}) {
      yield put({
        type: 'saveBread',
        payload: payload
      })
    },
    *fullScreenToggle({ payload }, { put }) {
      if (!payload.isShow) {
        exitFullscreen();
      } else {
        setFullscreen(document.getElementById(payload.name));
      }
      yield put({
        type: 'saveFullScreen',
        payload: { fullScreen: payload.isShow },
      });
    },
  },
  reducers: {
    saveBread(state={ breads: [] }, { payload }) {
      return {
        ...state,
        breads: payload
      };
    },
    changeLayoutCollapsed(state = { collapsed: true }, { payload }) {
      return {
        ...state,
        collapsed: payload,
      };
    },
    saveFullScreen(state = { fullScreen: true }, { payload }) {
      return {
        ...state,
        fullScreen: payload,
      };
    },
  },
};
export default GlobalModel;
